package com.hl.card.modular.pack.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hl.card.common.constant.factory.PageFactory;
import com.hl.card.common.persistence.dao.CommunityUserMapper;
import com.hl.card.common.persistence.dao.UserMapper;
import com.hl.card.common.persistence.model.*;
import com.hl.card.common.remote.user.RemoteUser;
import com.hl.card.common.remote.user.RemoteUserService;
import com.hl.card.common.remote.util.CommonUtilService;
import com.hl.card.common.util.HttpRequestUtil;
import com.hl.card.common.util.ResponseObject;
import com.hl.card.core.shiro.ShiroKit;
import com.hl.card.modular.pack.service.UserDataService;
import com.hl.card.common.util.CommonUtil;
import com.hl.card.common.util.HttpClientTool;
import com.hl.card.common.util.ResponseData;
import com.hl.card.modular.packBack.service.GoodsSevice;
import com.hl.card.modular.packBack.service.IProfitScaleService;
import com.hl.card.modular.packBack.service.ISalesDivisionService;
import com.hl.card.modular.system.service.ISysDicService;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.sql.JDBCType.NULL;

@Service
public class UserDataServiceImp extends ServiceImpl<UserMapper, User>  implements UserDataService {
    @Autowired
    private UserDataService userDataService;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    CommunityUserMapper communityUserMapper;
    @Autowired
    ISysDicService sysDicService;
    @Autowired
    private UserMapper userMapper;

    @Resource
    private GoodsSevice goodsSevice;

    @Resource
    private IProfitScaleService iProfitScaleService;

    @Resource
    private ISalesDivisionService iSalesDivisionService;

    @Resource
    private RemoteUserService remoteUserService;
    @Resource
    private CommonUtilService commonUtilService;

    @Autowired
    private ResponseData responseData;

    @Value("${uc.center}")
    private String userCenterUrl;
    /**
     * 修改会员性别
     *
     * @param userId
     * @return
     * @throws IOException
     */
    @Override
    public LogjnDay updateUserSex(String userId, String sex) throws IOException {
        String url =userCenterUrl+":8281/center/update";
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("sex", sex);
        String res ="";
        res = HttpClientTool.doPost(url, paramMap);
		/*res = HttpClient.httpsRequestImage(url, paramMap);*/
        System.out.println(res);
        JSONObject object=JSON.parseObject(res);
        JSONObject obj= (JSONObject) object.get("data");
        LogjnDay logjnDay =JSON.toJavaObject(obj,LogjnDay.class);
        return logjnDay;
    }
    /**
     * 修改头像路径
     *
     * @param userId img
     * @return
     * @throws IOException
     */
    @Override
    public User updateUserImg(String userId, String img) throws  IOException {
        String url =userCenterUrl+":8281/center/update";
        System.out.println(url);
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("img", img);
        String res = HttpClientTool.doPost(url, paramMap);
        JSONObject object=JSON.parseObject(res);
        JSONObject obj= (JSONObject) object.get("data");
        User user = JSON.toJavaObject(obj,User.class);
        return user;
    }
    @Override
    public Object updateUserName(String userId, String userName) throws IOException {
        String url =userCenterUrl+":8281/center/update";
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("userName", userName);
        String res =HttpClientTool.doPost(url, paramMap);
        JSONObject object=JSON.parseObject(res);
        RemoteUser remoteUser= JSONObject.parseObject(String.valueOf(object.get("user")),RemoteUser.class);
        User user=new User();
        user.setUserId(userId);
        user.setName(userName);
        if(remoteUser!=null){
            userMapper.updateUserInfo(user);
        }
        return user;
    }
    @Override
    public String getRegCode() {
        String  code=  CommonUtil.getItemID(6);
        Wrapper<User> warp=new EntityWrapper<User>();
        warp.eq("reg_code",code);
        User re = super.selectOne(warp);
        if(null!=re){
            code= getRegCode();
        }
        return code;
    }

    @Override
    public User ssouserToCarPackUser(RemoteUser remoteUser, User user) {
        user.setUserId(remoteUser.getUserId());
        user.setImg(remoteUser.getImg());
        Integer sex=2;
        String ssoSex=remoteUser.getSex();
        if (!StringUtils.isBlank(ssoSex)) {
            if (ssoSex.equals("0")) {
                sex = 0;
            }
            if (ssoSex.equals("1")) {
                sex = 1;
            }
        }
        user.setSex(sex);
        user.setAccount(remoteUser.getLoginAccount());
        try{
//            Date date=DateUtils.parseDate(remoteUser.getBirthday());
//            user.setBirthday(date);
        }catch (Exception e){
            e.printStackTrace();
        }
        user.setCreatetime(new Date());
        user.setName(remoteUser.getUserName());
        user.setEmail(remoteUser.getEmail());
        user.setPhone(remoteUser.getMobilePhone());
        user.setReg_code(getRegCode());
        return user;
    }

    /**
     * 检测用户token 合法性
     * @param token
     * @return
     */
    @Override
    public Boolean checkToken(String token) {
        String url=userCenterUrl+":808/checkToken";
        String param="token="+token;
        String res = HttpRequestUtil.sendGet(url, param);
        JSONObject jsonObject=JSON.parseObject(res);
        String code=jsonObject.getString("code");
        if(code.equals("1")){
            return true;
        }else{
            return false;
        }

    }

    public  Boolean checkStaticToken(String token) {
        String url=userCenterUrl+":808/checkToken";
        String param="token="+token;
        String res = HttpRequestUtil.sendGet(url, param);
        JSONObject jsonObject=JSON.parseObject(res);
        String code=jsonObject.getString("code");
        if(code.equals("1")){
            return true;
        }else{
            return false;
        }

    }
    /***
     * 检测卡包用户是否存在，没有就创建有就返回
     * @param userid
     * @return
     */
    @Override
    public User checkAndSaveUser(String userid) {
        User user=null;
        Wrapper<User> warp=new EntityWrapper<User>();
        warp.eq("user_id",userid);
        User re = super.selectOne(warp);
        return re;
    }

    /**
     * 消费金额
     */
    @Override
    public Object fraction(String code, Double amount) {
        Map<String,Object> map = new HashMap<>();
        SalesDivision salesDivision = iSalesDivisionService.selectByName(code);
        if(salesDivision == null){
            map.put("code",202);
            map.put("msg","该产品消费分润比例不存在");
            return  map;
        }
        ProfitScale profitScale = iProfitScaleService.selectByName(code);
        if(profitScale == null){
            map.put("code",203);
            map.put("msg","该产品销售分润比例不存在");
            return  map;
        }
        BigDecimal fractionAmount;
        if(salesDivision.getCalculationType() == 0){
            //TODO 需要取消*10,因为这是比豆和人民币的比率,最佳方法是通过配置来获取这个比例
            double rate = 1;
            fractionAmount = new BigDecimal(salesDivision.getProfitRatio() * amount/100 * rate).setScale(0, BigDecimal.ROUND_HALF_UP) ;
        }else{
            fractionAmount = new BigDecimal(salesDivision.getFixedAmount());
        }
        Integer member = (int)Math.ceil(fractionAmount.doubleValue() * profitScale.getMember() / 100);
        Integer partner = (int)Math.ceil(fractionAmount.doubleValue() * profitScale.getPartenr() / 100);
        Integer bibi = (int)Math.ceil(fractionAmount.doubleValue() * profitScale.getBibi() / 100);
        map.put("code",200);
        map.put("member",member);
        map.put("partner",partner);
        map.put("bibi",bibi);
        return map;
    }

    /**
     * 消费金额
     */
    @Override
    public Object fractionV1(String code, Double amount, String userId) {
//        Wrapper<User> wrapper=new EntityWrapper<User>();
//        wrapper.eq("user_id",userId);
//        User user=selectOne(wrapper);
//        String community = user.getIscommunityUser();
        Map<String,Object> map = new HashMap<>();

        SalesDivision salesDivision = iSalesDivisionService.selectByName(code);
        ProfitScale profitScale = iProfitScaleService.selectByName(code);
        String remarks = profitScale.getRemarks();
        String currency = "bd";
        int level = 0;
        if(StringUtils.isNotBlank(remarks)) {
            String[] awardType = remarks.split("-");
            try {
                level = Integer.parseInt(awardType[0]);
            } catch (NumberFormatException e) {
                level = 0;
            }

            if (awardType.length >= 2) {
                if("bd".equals(currency) || "htl".equals(currency)) {
                    currency = awardType[1];
                }
            }
        }
        if(salesDivision == null){
            map.put("code",202);
            map.put("msg","该产品消费分润比例不存在");
            return  map;
        }
        //ProfitScale profitScale = iProfitScaleService.selectByName(code);
        if(profitScale == null){
            map.put("code",203);
            map.put("msg","该产品销售分润比例不存在");
            return  map;
        }
        BigDecimal fractionAmount;
        if(salesDivision.getCalculationType() == 0){
            //TODO 需要取消*10,因为这是比豆和人民币的比率,最佳方法是通过配置来获取这个比例
            double rate = 1;
            fractionAmount = new BigDecimal(salesDivision.getProfitRatio() * amount/100 * rate).setScale(0, BigDecimal.ROUND_HALF_UP) ;
        }else{
            fractionAmount = new BigDecimal(salesDivision.getFixedAmount());
        }
        Integer member = (int)Math.ceil(fractionAmount.doubleValue() * profitScale.getMember() / 100);
        Integer partner = (int)Math.ceil(fractionAmount.doubleValue() * profitScale.getPartenr() / 100);
        Integer bibi = (int)Math.ceil(fractionAmount.doubleValue() * profitScale.getBibi() / 100);
        map.put("code",200);
        map.put("member", member);
        if(level == 1) {
            map.put("partner",partner);
            map.put("plantForm",0);
        }else if(level == 2) {
            map.put("partner",partner);
//            if(community!=null&&community.equals("1")) {//是社区管理员
                map.put("plantForm",bibi);
//            }else {
//                map.put("plantForm", 0);
//            }
        }else {
            map.put("partner",0);
            map.put("plantForm",0);
        }
        map.put("currency",currency);
        return map;
    }

    /**
     * 消费金额
     */
    @Override
    public Object fractionRateV1(String code) {
//        Wrapper<User> wrapper=new EntityWrapper<User>();
//        wrapper.eq("user_id",userId);
//        User user=selectOne(wrapper);
//        String community = user.getIscommunityUser();
        Map<String,Object> map = new HashMap<>();

        SalesDivision salesDivision = iSalesDivisionService.selectByName(code);
        ProfitScale profitScale = iProfitScaleService.selectByName(code);
        if(profitScale == null) {
            map.put("code",203);
            map.put("msg","该产品销售分润比例不存在");
            return map;
        }
        String remarks = profitScale.getRemarks();
        String currency = "bd";
        int level = 0;
        if(StringUtils.isNotBlank(remarks)) {
            String[] awardType = remarks.split("-");
            try {
                level = Integer.parseInt(awardType[0]);
            } catch (NumberFormatException e) {
                level = 0;
            }

            if (awardType.length >= 2) {
                if("bd".equals(currency) || "htl".equals(currency)) {
                    currency = awardType[1];
                }
            }
        }
        if(salesDivision == null){
            map.put("code",202);
            map.put("msg","该产品消费分润比例不存在");
            return  map;
        }
        //ProfitScale profitScale = iProfitScaleService.selectByName(code);
        if(profitScale == null){
            map.put("code",203);
            map.put("msg","该产品销售分润比例不存在");
            return  map;
        }
        if(salesDivision.getCalculationType() != 0){
            map.put("amount", salesDivision.getFixedAmount());
        }
        map.put("code",0);
        map.put("member", profitScale.getMember() / 100);
        if(level == 1) {
            map.put("partner",profitScale.getPartenr() / 100);
            map.put("parentPartner",0);
        }else if(level == 2) {
            map.put("partner",profitScale.getPartenr() / 100);
            map.put("parentPartner",profitScale.getBibi() / 100);
        }else {
            map.put("partner",0);
            map.put("parentPartner",0);
        }
        map.put("currency",currency);
        return map;
    }

    /**
     * 发送手机验证信息
     */
    @Override
    public Object outSendPhoneCode(String userId, String phoneNum) throws IOException{
        String url =userCenterUrl+":8281/center/sendPhoneCode";
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("phoneNum", phoneNum);
        String res ="";
        res = HttpClientTool.doPost(url, paramMap);
        System.out.println(res);
        JSONObject object=JSON.parseObject(res);
        JSONObject obj= (JSONObject) object.get("data");
        Object obj1=JSON.toJavaObject(obj,Object.class);
        return obj1;
    }
    /**
     *  绑定用户手机
     */
    @Override
    public Object outChangePhone(String userId, String newPhone, String verificode) throws IOException {
        String url = userCenterUrl+":8281/center/changePhone";
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("newPhone", newPhone);
        paramMap.put("verificode", verificode);
        String res ="";
        res = HttpClientTool.doPost(url, paramMap);
        System.out.println(res);
        JSONObject object=JSON.parseObject(res);
	     /*JSONObject obj= (JSONObject) object.get("data");
	     Object obj1=JSON.toJavaObject(obj,Object.class);*/
        return object;
    }
    @Override
    public Object modifyEmail(String userId, String addr, String phone, String code) {
        String url = userCenterUrl+":8281/center/changeMailByPhoneCode";
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("phone", phone);
        paramMap.put("addr", addr);
        paramMap.put("code", code);
        String res ="";
        try {
            res = HttpClientTool.doPost(url, paramMap);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println(res);
        JSONObject object=JSON.parseObject(res);
	     /*JSONObject obj= (JSONObject) object.get("data");
	     Object obj1=JSON.toJavaObject(obj,Object.class);*/
        return object;
    }
    /**
     * 修改用户密码
     *
     * @param userId
     * @return res
     * @throws IOException
     */
    @Override
    public Object modifyChangePwd(String userId, String sourcePwd, String loginPwd) throws IOException {
        String url =userCenterUrl+":8281/center/changePwd";
        Map<String, String> paramMap = new HashMap<>();
        paramMap.put("userId", userId);
        paramMap.put("sourcePwd", sourcePwd);
        paramMap.put("loginPwd",loginPwd);
        String res ="";
        res = HttpClientTool.doPost(url, paramMap);
        System.out.println(res);
        JSONObject object=JSON.parseObject(res);
	     /*JSONObject obj= (JSONObject) object.get("data");
	     Object obj1=JSON.toJavaObject(obj,Object.class);*/
        return object;
    }
    @Override
    public User selectUser(String userId) {
        User user = new User();
        user.setUserId(userId);
        return userMapper.selectUser(user);
    }
    @Override
    public ResponseData updateUserPayPasswordById(String userId, String newPassword) {
        User user0 = new User();
        user0.setUserId(userId);
        User  user=userMapper.selectOne(user0);
        String newUserPayPassword = ShiroKit.md5(newPassword, user.getSalt());
        user.setUserPayPassword(newUserPayPassword);
        int result=userMapper.updateUserPayPasswordById(user);
        if (result == 0) {
            responseData.setStatus("0");
            responseData.setData(null);
            responseData.setData("修改支付密码失败");
        } else {
            responseData.setData(user.getUserPayPassword());
            responseData.setStatus("1");
            responseData.setData("修改支付密码成功");
        }
        return responseData;
    }
    @Override
    public ResponseData saveUserPayPassword(String userId, String userPayPassword) {
        //对于以前的用户就用空盐
        User user0 = new User();
        user0.setUserId(userId);
        User  user=userMapper.selectOne(user0);
        String newUserPayPassword = ShiroKit.md5(userPayPassword, user.getSalt());
        user.setUserPayPassword(newUserPayPassword);
        int result=userMapper.saveUserPayPassword(user);
        if (result == 0) {
            responseData.setStatus("0");
            responseData.setData(null);
            responseData.setData("修改支付密码失败");
        } else {
            responseData.setData(user.getUserPayPassword());
            responseData.setStatus("1");
            responseData.setData("修改支付密码成功");
        }
        return responseData;
    }
    @Override
    public User findUserByRedCode(String regCode) {
        System.out.println("推荐注册码：" + regCode);
        User newUser=new User();
        newUser.setReg_code(regCode);
        User user=userMapper.selectOne(newUser);
        return user;
    }
    @Override
    public boolean checkPayPassword(String userId, String payPassWord) {
        User user=new User();
        user.setUserId(userId);
        User newUser=userMapper.selectOne(user);
        String checkPayPassWord=ShiroKit.md5(payPassWord, newUser.getSalt());
        if(newUser!=null){
            return checkPayPassWord.equals(newUser.getUserPayPassword());
        }
        return false;
    }
    /**
     * 这里返回的就是
     *
     * 1.用户类型 0 表示上级是和上上级都是普通用户 1 ，表示直接上级是群主2，表示上级的上级是群主
     * 2.两个用户id 上级的id 和上级的上级的id
     *
     * @param regCode
     * @return
     */
    @Override
    public Map<String,String> checkUserParentDegree(String regCode) {//推荐人的推荐码
        String userType = "0";
        String	user1id = "";//直接上级
        String	user2id = "";//上级的上级
        Map map = new HashMap();
        User user1 = findUserByRedCode(regCode);//上级推荐人
        String iscommunityUser = user1.getIscommunityUser();//判断上级是不是群主
        String refer_reg_code = user1.getRefer_reg_code();//上级的上级
        if (iscommunityUser != null && iscommunityUser.equals("1")) {//上级是群主
            userType = "1";
            user1id = user1.getUserId();//群主id
        } else if (!StringUtils.isBlank(refer_reg_code)) {//存在上级有上级
            User user2 = findUserByRedCode(refer_reg_code);//上级的上级
            String iscommunityUser2 = user2.getIscommunityUser();
            if (iscommunityUser2 != null && iscommunityUser2.equals("1")) {//上级的上级是群主
                userType = "2";
                user1id = user1.getUserId();//上级id
                user2id = user2.getUserId();//群主id
            }
        }
        map.put("userType", userType);
        map.put("user1id", user1id);
        map.put("user2id", user2id);
        return map;
    }

    /**
     * 经典三级关系查找
     * @param regCode
     * @return
     */
    @Override
    public Map<String, String> checkUserParentDegreeThree(String regCode) {
        String	user1id = "";//直接上级
        String	user2id = "";//上级的上级
        Map map = new HashMap();
        User user1 = findUserByRedCode(regCode);
        String refer_reg_code = user1.getRefer_reg_code();
        user1id = user1.getUserId();
         if (!StringUtils.isBlank(refer_reg_code)) {
             User user2 = findUserByRedCode(refer_reg_code);
             user2id = user2.getUserId();
        }
        map.put("user1id", user1id);
        map.put("user2id", user2id);
        return map;
    }

    @Override
    public Page<User> recommendByRegCode(Page<User> page, String regCode) {
//		SqlHelper.table(User.class);
        page.setRecords(userMapper.queryUserAndRecommendCount(page, regCode));
//		page=userMapper.queryUserAndRecommendCount(page, regCode);
        return page;
    }

    @Override
    public User selectByUserId(String userId) {
        User user=new User();
        user.setUserId(userId);
        return    userMapper.selectOne(user);
    }
    @Override
    public boolean checkRegCodeUsedLimitedByUserId(String userId) {
        Wrapper<User> wrapper1 = new EntityWrapper<>();
        wrapper1.eq("user_id", userId);
        User newUser = userDataService.selectOne(wrapper1);
        if(newUser != null) {
            return checkRegCodeUsedLimited(newUser.getReg_code());
        }
        return false;
    }

    @Override
    public boolean checkRegCodeUsedLimited(String referCode) {
        int referCodeCount;

        String countStr = stringRedisTemplate.opsForValue().get(referCode);
        if(StringUtils.isBlank(countStr)) {
            countStr = "0";
        }
        referCodeCount = Integer.parseInt(countStr);
        List<Map<String, Object>> list = sysDicService.selectListByCode("YQZCXZ");
        int max = -1;
        if(list != null) {
            String value = (String) list.get(0).get("MAX");
            if(StringUtils.isNotBlank(value)) {
                try {
                    max = Integer.parseInt(value);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        }

        if (referCodeCount >= max && max > 0) {
            System.out.println("推荐人奖励已达上限");
            return true;
        }
        return false;
    }

    @Override
    public int getRegCodeUsedCountByUserId(String userId) {
        Wrapper<User> wrapper1 = new EntityWrapper<>();
        wrapper1.eq("user_id", userId);
        User newUser = userDataService.selectOne(wrapper1);
        if(newUser != null) {
            return getRegCodeUsedCount(newUser.getReg_code());
        }
        return -1;
    }
    @Override
    public int getRegCodeUsedCount(String referCode){
        int referCodeCount;

        String countStr = stringRedisTemplate.opsForValue().get(referCode);
        if(StringUtils.isBlank(countStr)) {
            countStr = "0";
        }
        referCodeCount = Integer.parseInt(countStr);
        return referCodeCount;
    }
    @Override
    public int getRegCodeRemainCountByUserId(String userId){
        Wrapper<User> wrapper1 = new EntityWrapper<>();
        wrapper1.eq("user_id", userId);
        User newUser = userDataService.selectOne(wrapper1);
        if(newUser != null) {
            return getRegCodeRemainCount(newUser.getReg_code());
        }
        return -1;
    }
    @Override
    public int getRegCodeRemainCount(String referCode){
        int referCodeCount;

        String countStr = stringRedisTemplate.opsForValue().get(referCode);
        if(StringUtils.isBlank(countStr)) {
            countStr = "0";
        }
        referCodeCount = Integer.parseInt(countStr);
        List<Map<String, Object>> list = sysDicService.selectListByCode("YQZCXZ");
        int max = -1;
        if(list != null) {
            String value = (String) list.get(0).get("MAX");
            if(StringUtils.isNotBlank(value)) {
                try {
                    max = Integer.parseInt(value);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        }
        return max - referCodeCount;
    }

    @Override
    public int getRegCodeUsedLimitCount() {
        List<Map<String, Object>> list = sysDicService.selectListByCode("YQZCXZ");
        int max = -1;
        if(list != null) {
            String value = (String) list.get(0).get("MAX");
            if(StringUtils.isNotBlank(value)) {
                try {
                    max = Integer.parseInt(value);
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        }
        return max;
    }

    @Override
    public Page<User> selectMultiCondition(User user,String beginTime,String endTime) {
        Page<User> page = new PageFactory<User>().defaultPage();
        Wrapper<User> wrapper = new EntityWrapper<>();
        wrapper.orderBy("createtime",false);
        if(!StringUtils.isEmpty(beginTime)){
            wrapper.ge("createtime",beginTime.trim());
        }
        if(!StringUtils.isEmpty(endTime)){
            System.out.println("endTime:"+endTime);
            wrapper.le("createtime",endTime.trim());
        }
        if (!StringUtils.isEmpty(user.getName())) {
            wrapper.eq("name", user.getName().trim());
        }
        if (!StringUtils.isEmpty( user.getAccount())) {
            wrapper.eq("account", user.getAccount().trim());
        }
        if(!StringUtils.isEmpty(user.getReg_code())){
            wrapper.eq("reg_code",user.getReg_code().trim());
        }
        if(!StringUtils.isEmpty(user.getRefer_reg_code())){
            wrapper.eq("refer_reg_code",user.getRefer_reg_code().trim());
        }
        if(!StringUtils.isEmpty(user.getUserId())){
            wrapper.eq("user_id",user.getUserId().trim());
        }
        wrapper.isNotNull("reg_code");
        Page<User> dPage = selectPage(page, wrapper);
        return dPage;
    }

}
